package com.github.ylt.protocol.http;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.Function;

public final class ImmutableHeaders extends Headers {
    private final Headers headers;
    public ImmutableHeaders(Headers headers) {
        this.headers = headers;
    }

    @Override
    public int size() {
        return headers.size();
    }

    @Override
    public boolean isEmpty() {
        return headers.isEmpty();
    }

    @Override
    public boolean containsKey(Object key) {
        return headers.containsKey(key);
    }

    @Override
    public boolean containsValue(Object value) {
        return headers.containsValue(value);
    }

    @Override
    public List<String> get(Object key) {
        return headers.get(key);
    }

    public String getHeaderString() {
        StringBuilder builder = new StringBuilder();
        this.headers.forEach((k,v)->{
            int size = v.size();
            if(size > 1){
                v.forEach(v1-> builder.append(k).append(": ").append(v1).append("\r\n"));
            }else{
                builder.append(k).append(": ").append(v.getFirst()).append("\r\n");
            }
        });
        builder.append("\r\n");
        return builder.toString();
    }

    @Override
    public List<String> put(String key, List<String> value) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public List<String> remove(Object key) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public void putAll(Map<? extends String, ? extends List<String>> m) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public void clear() {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public Set<String> keySet() {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public Collection<List<String>> values() {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public Set<Entry<String, List<String>>> entrySet() {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public void replaceAll(BiFunction<? super String, ? super List<String>, ? extends List<String>> function) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public List<String> putIfAbsent(String key, List<String> value) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public boolean replace(String key, List<String> oldValue, List<String> newValue) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public List<String> replace(String key, List<String> value) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public List<String> computeIfAbsent(String key, Function<? super String, ? extends List<String>> mappingFunction) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public List<String> computeIfPresent(String key, BiFunction<? super String, ? super List<String>, ? extends List<String>> remappingFunction) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public List<String> compute(String key, BiFunction<? super String, ? super List<String>, ? extends List<String>> remappingFunction) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public List<String> merge(String key, List<String> value, BiFunction<? super List<String>, ? super List<String>, ? extends List<String>> remappingFunction) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public boolean remove(Object key, Object value) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public void forEach(BiConsumer<? super String, ? super List<String>> action) {
        throw new UnsupportedOperationException("不支持此操作");
    }

    @Override
    public List<String> getOrDefault(Object key, List<String> defaultValue) {
        throw new UnsupportedOperationException("不支持此操作");
    }
}
